package com.yy.micro.magic.data.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yy.micro.magic.data.entity.CodeMapEntity;
import com.yy.micro.magic.data.model.vo.JpaObjectWithDynamicFieldsVo;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Transient;

public class CodeMapVo extends JpaObjectWithDynamicFieldsVo {

    private Long codeId;

    private String codeName;

    private boolean disable;

    private  String description;

    @Transient
    private List<CodeItemVo> items;
    private Set<Long> itemList = new LinkedHashSet<>();


    public Long getCodeId() {
        return codeId;
    }

    public void setCodeId(final Long codeId) {
        this.codeId = codeId;
    }

    public String getCodeName() {
        return codeName;
    }

    public void setCodeName(final String codeName) {
        this.codeName = codeName;
    }

    public boolean isDisable() {
        return disable;
    }

    public void setDisable(final boolean disable) {
        this.disable = disable;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public List<CodeItemVo> getItems() {
        return items;
    }

    public void setItems(final List<CodeItemVo> items) {
        this.items = items;
    }

    public void setItemList(final Set<Long> itemList) {
        this.itemList = itemList;
    }

    public Set<Long> getItemList() {
        return itemList;
    }

    @JsonIgnore
    public static CodeMapVo create(){
        return new CodeMapVo();
    }

    @JsonIgnore
    public CodeMapVo from(final CodeMapEntity from) {
        super.from(from);
        setCodeId(from.getCodeId());
        setDescription(from.getDescription());
        setDisable(from.isDisable());
        setCodeName(from.getCodeName());
        setItemList(from.getItemList());
        return this;
    }

    @JsonIgnore
    public CodeMapEntity to(){
        CodeMapEntity entity = new CodeMapEntity();
        super.to(entity);
        entity.setCodeId(getCodeId());
        entity.setDescription(getDescription());
        entity.setDisable(isDisable());
        entity.setItemList(getItemList());
        entity.setCodeName(getCodeName());
        return entity;
    }
}
